//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Windows.Data;

namespace OpenLS.Chart.UI.Internals
{
    public class SeriesObserverFactory: IMultiValueConverter
    {

        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            object value = values[0];
            BarGrouping grouping;
            if (values[1] is Grouping)
            {
                switch ((Grouping)values[1])
                {
                    case Grouping.Standard:
                        grouping = BarGrouping.Standard; break;
                    case Grouping.Stacked: grouping = BarGrouping.Stacked; break;
                    case Grouping.PercentStacked: grouping = BarGrouping.PercentStacked; break;
                    default: throw new NotSupportedException();
                }
            }
            else
                grouping = (BarGrouping)values[1];
            if (value is ObservableCollection<AreaSeries>)
                return new SeriesObserver<AreaSeries>((ObservableCollection<AreaSeries>)value, grouping);
            if (value is ObservableCollection<BarSeries>)
                return new SeriesObserver<BarSeries>((ObservableCollection<BarSeries>)value, grouping);
            if (value is ObservableCollection<LineSeries>)
                return new SeriesObserver<LineSeries>((ObservableCollection<LineSeries>)value, grouping);
            throw new NotImplementedException();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}